﻿<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="author" content="火星科技 http://mars2d.cn " />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
    <link rel="shortcut icon" type="image/x-icon" href="/img/favicon/favicon.ico" />

    <meta name="keywords" content="火星科技,leaflet,mars2d,GIS,marsgis,二维,地图,地球,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 leaflet leaflet开发 leaflet框架 二维 地图 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 二维地图 全景漫游 地理信息系统 云GIS 二维GIS GIS平台 WebGIS"
    />

    <title>Mars2D地图 |二维地图| 火星科技|合肥火星科技|合肥火星科技有限公</title>

    <!--第三方lib-->
    <script
      type="text/javascript"
      src="/lib/include-lib.js"
      libpath="/lib/"
      include="jquery,font-awesome,bootstrap,layer,haoutil,mars2d,turf"
    ></script>

    <link href="/css/style.css" rel="stylesheet" />
  </head>

  <body>
    <div id="mars2dContainer" class="mars2d-container"></div>

    <!-- demo面板 -->
    <div class="infoview">
      缓冲半径：
      <input id="txtRadius" type="number" value="1" min="1" step="1" max="999" class="form-control" style="width: 100px" />（公里）

      <input type="button" class="btn btn-primary" value="点" onclick="drawPoint()" />
      <input type="button" class="btn btn-primary" value="线" onclick="drawPolyline()" />
      <input type="button" class="btn btn-primary" value="面" onclick="drawPolygon()" />
      <input type="button" class="btn btn-primary" value="清除" onclick="deleteAll()" />
    </div>

    <script src="/js/common.js"></script>
    <script src="./map.js"></script>
    <script type="text/javascript">
      "use script" //开发环境建议开启严格模式
      $("#txtRadius").change(function (e) {
        if (lastgeojson) {
          updateBuffer()
        }
      })

      function drawPoint() {
        deleteAll()

        graphicLayer.startDraw({
          type: "point",
          style: {
            pixelSize: 6,
            color: "#0000ff"
          }
        })
      }

      function drawPolyline() {
        deleteAll()

        graphicLayer.startDraw({
          type: "polyline",
          style: {
            width: 3,
            color: "#0000ff"
          }
        })
      }

      function drawPolygon() {
        deleteAll()

        graphicLayer.startDraw({
          type: "polygon",
          style: {
            fill: true,
            fillColor: "#0000ff",
            fillOpacity: 0.3,
            outline: true,
            outlineWidth: 2,
            outlineColor: "#254dc4",
            outlineOpacity: 1
          }
        })
      }

      function deleteAll() {
        graphicLayer.clear()
        resultLayer.clear()
        lastgeojson = null
      }

      let lastgeojson

      function updateBuffer(layer) {
        let width = Number($("#txtRadius").val()) //km

        let buffere
        try {
          let geojson = layer ? layer.toGeoJSON() : lastgeojson
          geojson.properties = {}

          buffere = turf.buffer(geojson, width, { units: "kilometers" })

          lastgeojson = geojson
        } catch (e) {
          console.log("缓冲分析异常", e)
        }
        if (!buffere) {
          return
        }
        let graphicsOptions = mars2d.Util.geoJsonToGraphics(buffere, {
          type: "polygon",
          style: {
            fillColor: "#ff0000",
            fillOpacity: 0.3,
            outline: false
          }
        })
        resultLayer.clear()
        let graphic = resultLayer.addGraphic(graphicsOptions)
        graphic.bringToBack()
      }
    </script>
  </body>
</html>
